<?php
namespace Modules\Activity\Http\Controllers\Client\Fudai;

use Illuminate\Http\Request;
use Illuminate\Routing\Controller;

// use \Modules\Asset\Entities\PackageSku;
use \Modules\Activity\Entities\Fudai\Record;
use \Modules\Activity\Entities\Fudai\Activity;

use Validator;
use ThrowException;
use Auth;
use Setting;
use DB;

// 开赏活动
class RecordController extends Controller
{
    // 数量统计
    public function total(Request $req, $uuid) 
    {
        $rule = [
        ];
        Validator::make($req->all(), $rule)->fails() && ThrowException::BadRequest(); 

        $node = Activity::getEntity([
            'uuid' => $uuid
        ]);

        $options = $req->all();

        $allTotal = Record::where('node_id', $node->id)->sum('total');

        return [
            'all' => $allTotal
        ];
    }

    // 房间列表
    public function index(Request $req, $uuid)
    {
        $rule = [
        ];
        Validator::make($req->all(), $rule)->fails() && ThrowException::BadRequest();

        $node = Activity::getEntity([
            'uuid' => $uuid
        ]);

        $options = $req->all();

        $builder = Record::where('node_id', $node->id);

        $setting = @Setting::get('sys_fudai_record_list') ?: [];
        if (@$setting['level_ids']) {
            $builder = $builder->whereIn('level', $setting['level_ids']);
        }
        if ($req->input('checkType') && $req->checkType > 0) {
            $builder = $builder->where('level', $req['checkType']);
        }

        $options['builder'] = $builder;

        $list = Record::getList($options);

        return $list->generateListResponse();
    }
}
